package com.ourteam.product.requirement.dao.impl;

import com.ourteam.product.requirement.dao.IProductIssueAttachDAO;
import com.ourteam.product.requirement.dao.ProductIssueAttach;
import com.ourteam.product.requirement.dao.ProductIssueAttachDAOQueryBean;

import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;

import org.springframework.jdbc.core.RowMapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * Template Name : DAO服务对象
 * Template Version : 1
 * Template Last Modfiy Date : Fri Nov 17 11:00:11 CST 2017
 * Auto Generate Date : 2018-05-03 16:45:43
  * Warning ! This file will be overwrite when regenerate !
  *
 */
public class AbstractProductIssueAttachDAOJdbcImpl extends AbstractSpringDAO
    implements IProductIssueAttachDAO {
    public static final String[] ENTITY_FIELDS = new String[] {
            Id, IssueId, AttachFileName, AttachFilePath, UploadTime,
            UploadUserId, Status, Remarks, UploadUserName, UploadUserPhoto
        };
    public static final String[] ENTITY_PROPERTIES = new String[] {
            _DataObjectProperty.Id, _DataObjectProperty.IssueId,
            _DataObjectProperty.AttachFileName,
            _DataObjectProperty.AttachFilePath, _DataObjectProperty.UploadTime,
            _DataObjectProperty.UploadUserId, _DataObjectProperty.Status,
            _DataObjectProperty.Remarks, _DataObjectProperty.UploadUserName,
            _DataObjectProperty.UploadUserPhoto
        };
    public static final String[] ENTITY_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] { Id };
    public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {  };
    private static String relatedJoinSQL = null;
    private static String basicFilterSQL = null;
    private DataAccessObjectHelper<ProductIssueAttach, ProductIssueAttachDAOQueryBean> daoHelper;

    public AbstractProductIssueAttachDAOJdbcImpl() {
        super();
        daoHelper = new DataAccessObjectHelper<ProductIssueAttach, ProductIssueAttachDAOQueryBean>(this);
    }

    protected String getEntityName() {
        return EntityName;
    }

    protected String[] getEntityFields() {
        return ENTITY_FIELDS;
    }

    protected String[] getEntityProperties() {
        return ENTITY_PROPERTIES;
    }

    protected String[] getEntityPKFields() {
        return ENTITY_PK_FIELDS;
    }

    protected String[] getEntityAutoGenPKFields() {
        return ENTITY_AUTO_GEN_PK_FIELDS;
    }

    protected String[] getEntityUniqueFields() {
        return ENTITY_UNIQUE_FIELDS;
    }

    protected String getBaiscQueryFilter() {
        if (basicFilterSQL == null) {
            StringBuffer basicFilterSQLbuffer = new StringBuffer();

            basicFilterSQL = basicFilterSQLbuffer.toString();
        }

        return basicFilterSQL;
    }

    protected String getRelatedJoinSQL() {
        if (relatedJoinSQL == null) {
            StringBuffer relatedJoinSQLBuffer = new StringBuffer();

            relatedJoinSQLBuffer.append(" LEFT JOIN ")
                                .append(com.ourteam.system.dao.ISysUserDAO.EntityName)
                                .append(" RELATED_X8D4OX_SysUser ");

            relatedJoinSQLBuffer.append(" ON ( ");

            relatedJoinSQLBuffer.append(StringUtils.replace(
                    com.ourteam.system.dao.ISysUserDAO.Id,
                    com.ourteam.system.dao.ISysUserDAO.EntityName + ".",
                    "RELATED_X8D4OX_SysUser."));
            relatedJoinSQLBuffer.append(" = ").append(UploadUserId);

            relatedJoinSQLBuffer.append(" ) ");

            relatedJoinSQL = relatedJoinSQLBuffer.toString();
        }

        return relatedJoinSQL;
    }

    /**
         * Check Data Unique
         * @param aProductIssueAttach
         * @throws Exception
         */
    public boolean checkIsUnique(ProductIssueAttach aProductIssueAttach)
        throws Exception {
        if (aProductIssueAttach == null) {
            return true;
        }

        List valueList = new ArrayList();

        List pkValueList = new ArrayList();

        pkValueList.add(aProductIssueAttach.getId());

        return isUnique(valueList.toArray(new Object[valueList.size()]),
            pkValueList.toArray(new Object[pkValueList.size()]));
    }

    /**
     * Insert Data
     * @param aProductIssueAttach
     * @throws Exception
     */
    public void insert(ProductIssueAttach aProductIssueAttach)
        throws Exception {
        super.doInsert(aProductIssueAttach);
    }

    /**
         * Batch Insert Datas
         * @param aProductIssueAttach
         * @throws Exception
         */
    public void batchInsert(ProductIssueAttach[] aProductIssueAttachs)
        throws Exception {
        super.doBatchInsert(aProductIssueAttachs);
    }

    /**
         * Delete Data
         * @param  final long id         *
         * @throws Exception
         */
    public void delete(final long id) throws Exception {
        super.doDeleteById(new Object[] { new Long(id) });
    }

    /**
     * Delete Datas
     * @param queryBean
     * @throws Exception
     */
    public void delete(ProductIssueAttachDAOQueryBean queryBean)
        throws Exception {
        super.doDeleteByQuery(queryBean);
    }

    public void delete(ProductIssueAttach aProductIssueAttach)
        throws Exception {
        delete(aProductIssueAttach.getId());
    }

    /**
     * Update Data Selective
     * @param aProductIssueAttach
     * @throws Exception
     */
    public void update(ProductIssueAttach aProductIssueAttach)
        throws Exception {
        if (aProductIssueAttach.getId() == 0) {
            throw new Exception(
                "Can not update object data whith out primary key value");
        }

        super.doUpdate(aProductIssueAttach);

        ProductIssueAttach tempObj = findById(aProductIssueAttach.getId());

        if (tempObj != null) {
            PropertyUtils.copyProperties(aProductIssueAttach, tempObj);
        }
    }

    /**
     * Batch Update Datas
     * @param aProductIssueAttachs[]
     * @throws Exception
     */
    public void batchUpdate(ProductIssueAttach[] aProductIssueAttachs)
        throws Exception {
        super.doBatchUpdate(aProductIssueAttachs);
    }

    /**
         * Update Data By Condictions
         * @param aProductIssueAttach
         * @param aValueCriteria
         * @param aTransaction
         * @throws Exception
         */
    public void update(ProductIssueAttach aProductIssueAttach,
        ProductIssueAttachDAOQueryBean aQueryBean) throws Exception {
        super.doUpdateByQuery(aProductIssueAttach, aQueryBean);
    }

    /**
     * Update Data By Condictions
     * @param aQueryBean
     * @throws Exception
     */
    public void update(ProductIssueAttachDAOQueryBean aQueryBean)
        throws Exception {
        super.doUpdateByQuery(aQueryBean);
    }

    protected void checkNullValue(ProductIssueAttach aProductIssueAttach)
        throws Exception {
    }

    /**
     * Get Data By ID
     * @param  final long id         * @return  ${businessObject.name}
     * @throws Exception
     */
    public ProductIssueAttach findById(final long id) throws Exception {
        ProductIssueAttachDAOQueryBean queryBean = new ProductIssueAttachDAOQueryBean();

        ProductIssueAttachDAOQueryBean.Criteria criteria = queryBean.createCriteria();

        criteria.andIdEqualTo(id);

        //queryBean.setDistinct(true);
        ProductIssueAttach[] ProductIssueAttachs = query(queryBean);

        if (ProductIssueAttachs.length == 0) {
            return null;
        } else {
            return ProductIssueAttachs[0];
        }
    }

    /**
         * Query Data
         * @param queryBean
         * @return ProductIssueAttach[]
         * @throws Exception
         */
    public ProductIssueAttach[] query(ProductIssueAttachDAOQueryBean queryBean)
        throws Exception {
        List result = super.doQuery(queryBean,
                new JdbcProductIssueAttachRowMapper());

        return (ProductIssueAttach[]) result.toArray(new ProductIssueAttach[result.size()]);
    }

    /**
     * Query ${businessObject.name} Selective
     * @param queryBean
     * @return Map[]
     * @model
     * @throws Exception
     */
    public Map<String, Object>[] querySelective(
        ProductIssueAttachDAOQueryBean queryBean) throws Exception {
        if (queryBean.getSelectProperties().isEmpty()) {
            queryBean.addAllSelectProperties();
        }

        return super.doQuerySelective(queryBean);
    }

    /**
     * Query Data Count
     * @param queryBean
     * @return int
     * @throws Exception
     */
    public int queryCount(ProductIssueAttachDAOQueryBean queryBean)
        throws Exception {
        return super.doQueryCount(queryBean);
    }

    public void synchronize(ProductIssueAttach[] aProductIssueAttachs,
        ProductIssueAttachDAOQueryBean queryBean) throws Exception {
        daoHelper.synchronize(aProductIssueAttachs, queryBean);
    }

    public void synchronize(ProductIssueAttach[] aProductIssueAttachs,
        ProductIssueAttachDAOQueryBean queryBean,
        net.dao.IDataAccessInterface.ISynchronizeCallback<ProductIssueAttach> callBack)
        throws Exception {
        daoHelper.synchronize(aProductIssueAttachs, queryBean, callBack);
    }

    public static class JdbcProductIssueAttachRowMapper implements RowMapper<ProductIssueAttach> {
        public ProductIssueAttach mapRow(ResultSet resultSet, int arg1)
            throws SQLException {
            ProductIssueAttach object = new ProductIssueAttach();

            int columnIndex = 1;

            int __dataType;

            try {
                Object id = null;

                id = resultSet.getObject(columnIndex++);

                object.setIdNull(resultSet.getBoolean(columnIndex++));

                if (id != null) {
                    setBeanValue(object, _DataObjectProperty.Id, id);
                }

                Object issueId = null;

                issueId = resultSet.getObject(columnIndex++);

                object.setIssueIdNull(resultSet.getBoolean(columnIndex++));

                if (issueId != null) {
                    setBeanValue(object, _DataObjectProperty.IssueId, issueId);
                }

                Object attachFileName = null;

                attachFileName = resultSet.getObject(columnIndex++);

                object.setAttachFileNameNull(resultSet.getBoolean(columnIndex++));

                if (attachFileName != null) {
                    setBeanValue(object, _DataObjectProperty.AttachFileName,
                        attachFileName);
                }

                Object attachFilePath = null;

                attachFilePath = resultSet.getObject(columnIndex++);

                object.setAttachFilePathNull(resultSet.getBoolean(columnIndex++));

                if (attachFilePath != null) {
                    setBeanValue(object, _DataObjectProperty.AttachFilePath,
                        attachFilePath);
                }

                Object uploadTime = null;

                __dataType = resultSet.getMetaData().getColumnType(columnIndex);

                if ((__dataType == java.sql.Types.DATE) ||
                        (__dataType == java.sql.Types.TIME) ||
                        (__dataType == java.sql.Types.TIMESTAMP)) {
                    uploadTime = resultSet.getTimestamp(columnIndex++);
                } else {
                    uploadTime = resultSet.getObject(columnIndex++);
                }

                object.setUploadTimeNull(resultSet.getBoolean(columnIndex++));

                if (uploadTime != null) {
                    setBeanValue(object, _DataObjectProperty.UploadTime,
                        uploadTime);
                }

                Object uploadUserId = null;

                uploadUserId = resultSet.getObject(columnIndex++);

                object.setUploadUserIdNull(resultSet.getBoolean(columnIndex++));

                if (uploadUserId != null) {
                    setBeanValue(object, _DataObjectProperty.UploadUserId,
                        uploadUserId);
                }

                Object status = null;

                status = resultSet.getObject(columnIndex++);

                object.setStatusNull(resultSet.getBoolean(columnIndex++));

                if (status != null) {
                    setBeanValue(object, _DataObjectProperty.Status, status);
                }

                Object remarks = null;

                remarks = resultSet.getObject(columnIndex++);

                object.setRemarksNull(resultSet.getBoolean(columnIndex++));

                if (remarks != null) {
                    setBeanValue(object, _DataObjectProperty.Remarks, remarks);
                }

                Object uploadUserName = null;

                uploadUserName = resultSet.getObject(columnIndex++);

                object.setUploadUserNameNull(resultSet.getBoolean(columnIndex++));

                if (uploadUserName != null) {
                    setBeanValue(object, _DataObjectProperty.UploadUserName,
                        uploadUserName);
                }

                Object uploadUserPhoto = null;

                uploadUserPhoto = resultSet.getObject(columnIndex++);

                object.setUploadUserPhotoNull(resultSet.getBoolean(
                        columnIndex++));

                if (uploadUserPhoto != null) {
                    setBeanValue(object, _DataObjectProperty.UploadUserPhoto,
                        uploadUserPhoto);
                }

                return object;
            } catch (Exception e) {
                throw new SQLException(e.getMessage());
            }
        }
    }
}
